""" System imports """
import os,sys
import logging
import threading

""" Other modules """
import pygame

""" Game """
from constants import *
import font
import dialog
import inputhandler
from mixboard import mixboard
from ui import menu
import session

""" Set up logging """
_log = logging.getLogger("epicquest.mainmenu")

class MainMenu():
    
    nesfont = None
    bignesfont = None
    menu = None
    
    def __init__(self):
        self.bignesfont = font.Font(NES_FONT, (255, 255, 255))
        self.bignesfont.set_scale(2)
        self.nesfont = font.Font(NES_FONT, (255, 255, 255))
        self.menu = menu.Menu(self.bignesfont, ["SECRET!","","New","Load","Exit"],3)
        self.session = session.Session()
        self.menu.move_cursor(1)
        self.menu.move_cursor(1)
    
    def update(self):
        if inputhandler.is_pressed(DOWN):
            self.menu.move_cursor(1)
            self.session.update_state('menuchoice',self.menu.get_option())
        if inputhandler.is_pressed(UP):
            self.menu.move_cursor(-1)
            self.session.update_state('menuchoice',self.menu.get_option())
       
        # If you press start, check which option you're on!
        if inputhandler.is_pressed(START):
            option, text = self.menu.get_option()
            print "You pressed " + text
            if option == 2:
                pygame.mixer.fadeout(500)
                pygame.time.delay(500)
                return 1
            if option == 3:
                pass
            if option == 4:
                raise SystemExit
            if option == 0:
                print "Super secret! YAAAAAY!"
            
    def exit_menu(self):
        mixboard.fadeout_music(500)
    
    def draw(self, surface):
        # Render text with the font
        self.bignesfont.render_center("Epic Quest", surface, False, 128)
        self.menu.draw(surface, ((SCREEN_SIZE[0] - self.menu.width) / 2, SCREEN_SIZE[1] / 2))
        
    def end_session(self):
        pass